package com.team.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.team.entity.IdeaComment;
import com.team.util.DbHelp;
import com.team.util.ResultSetPackge;

public class IdeaCommentDao {
	private DbHelp<IdeaComment> db = new DbHelp<IdeaComment>();
	
	public int save(IdeaComment ideaComment){
		String sql= "insert into t_ideacomment(content,createtime,t_idea_id,t_user_id)values(?,?,?,?)";
		return db.executeUpdateSql(sql, ideaComment.getContent(),ideaComment.getCreateTime(),ideaComment.getIdeaId(),ideaComment.getUserId());
	}

	public List<IdeaComment> selectByIdeaId(int id) {
			String sql = "select id,content,createtime,t_idea_id,t_user_id from t_ideacomment where t_idea_id = ?"; 
			return db.exeSelectForList(sql, new PackgeIdeaComment(), id);
	
		
	}
	
	private class PackgeIdeaComment implements ResultSetPackge<IdeaComment> {

		public IdeaComment packgeResultSet(ResultSet rs) throws SQLException {
				IdeaComment ideaComment = new IdeaComment();
				ideaComment.setId(rs.getInt("id"));
				ideaComment.setContent(rs.getString("content"));
				ideaComment.setCreateTime("createtime");
				ideaComment.setIdeaId(rs.getInt("t_idea_id"));
				ideaComment.setUserId(rs.getInt("t_user_id"));
				
			return ideaComment;
		}
		
	}

}
